package com.study.design.pattern.pattern.creational.builder;

/**
 * @Author: gongsl
 * @Date: 2025-02-16 11:33
 * @description:
 */
public class Person {
    private Integer id;
    private String name;
    private String gender;

    /**
     * 通过builder方法返回PersonBuilder
     */
    public static PersonBuilder builder(){
        return new PersonBuilder();
    }

    public Person(Integer id, String name, String gender) {
        this.id = id;
        this.name = name;
        this.gender = gender;
    }

    /*public Person(PersonBuilder builder){
        this.id = builder.builderId;
        this.name = builder.builderName;
        this.gender = builder.builderGender;
    }*/

    @Override
    public String toString() {
        return "Person(id=" + this.id + ", name=" + this.name + ", gender=" + this.gender + ")";
    }

    public static class PersonBuilder {
        private Integer builderId;
        private String builderName;
        private String builderGender;

        public PersonBuilder builderId(Integer builderId) {
            this.builderId = builderId;
            return this;
        }

        public PersonBuilder builderName(String builderName) {
            this.builderName = builderName;
            return this;
        }

        public PersonBuilder builderGender(String builderGender) {
            this.builderGender = builderGender;
            return this;
        }

        /**
         * 通过build方法返回Person
         */
        public Person build() {
            return new Person(this.builderId, this.builderName, this.builderGender);
        }

        /*public Person build() {
            return new Person(this);
        }*/
    }
}
